import 'package:stage_app/model/test_entity.dart';

testEntityFromJson(TestEntity data, Map<String, dynamic> json) {
	if (json['username'] != null) {
		data.username = json['username']?.toString();
	}
	if (json['password'] != null) {
		data.password = json['password']?.toString();
	}
	if (json['roles'] != null) {
		data.roles = new List<Role>();
		(json['roles'] as List).forEach((v) {
			data.roles.add(new Role().fromJson(v));
		});
	}
	return data;
}

Map<String, dynamic> testEntityToJson(TestEntity entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['username'] = entity.username;
	data['password'] = entity.password;
	if (entity.roles != null) {
		data['roles'] =  entity.roles.map((v) => v.toJson()).toList();
	}
	return data;
}

roleFromJson(Role data, Map<String, dynamic> json) {
	if (json['id'] != null) {
		data.id = json['id']?.toInt();
	}
	if (json['name'] != null) {
		data.name = json['name']?.toString();
	}
	return data;
}

Map<String, dynamic> roleToJson(Role entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['id'] = entity.id;
	data['name'] = entity.name;
	return data;
}